package com.manager.web;


import com.manager.service.PetService;
import com.manager.service.StoreService;
import com.manager.entity.Store;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/store")
public class StoreController {
    @Autowired
    private StoreService storeService;
    @Autowired
    private PetService petService;

    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public String storelist() {
        return "storelist";
    }

    /*导航到商店注册页，需要userid【通行证。】*/
    @RequestMapping(value = "/storeregisterpage", method = RequestMethod.GET)
    public String storeregisterpage(@RequestParam("userid") String userid, Model model) {
        model.addAttribute("userid", userid);
        return "storeregisterpage";
    }

    /*商店注册行为，写好了。*/
    @RequestMapping(value = "/storeregisteraction", method = RequestMethod.GET)
    @ResponseBody
    public Object register(@RequestParam("userid") String userid, @RequestParam("storeid") String storeid, @RequestParam("description") String description) {
        return storeService.register(userid, storeid, description);
    }

    @RequestMapping(value = "/mystorepage/{storeid}", method = RequestMethod.GET)
    public String mystorepage(@PathVariable("storeid") String storeid, @RequestParam("userid") String userid, Model model) {
        /*todo 多一个页码？？【ok？？？】返回页面？？+ajax？调用有问题？【刷新页面？？？下一页刷新页面？？？改变页码？根据页码？】*/
        model.addAttribute("userid", userid);

        /*todo 要删除吗？？？？【？？？】*/
        Map<String,Object> mypetshowList = petService.getAllPetInfoByStoreid(storeid,1);

        model.addAttribute("mypetshowlist", mypetshowList);
        return "mystore";
    }


    @RequestMapping("/allstore")
    public String allstore(Model model) {
        List<Store> allstorelist = storeService.getallstore();
        model.addAttribute("allstorelist", allstorelist);
        return "allstore";
    }

    @RequestMapping(value = "/mystore", method = RequestMethod.GET)
    @ResponseBody
    public Map<String,Object> mystore(@RequestParam("storeid") String storeid, @RequestParam("userid") String userid, @RequestParam("page") int page) {
        Map<String,Object> mypetshowList = petService.getAllPetInfoByStoreid(storeid,page);/*五个？【】*/
        return mypetshowList;
    }
}